top=..
SRC=./src
CFLAGS= -ansi  -pedantic-errors -Wall -Werror 
CFLAGS= -D _GNU_SOURCE
COMPILEONLY= -c 
BIN=bin
OBJ=obj
CM=Common
PB=Public
ST=Static
DN=Dinamic
RL=../$(CM)/$(BIN)/Release

CC=gcc


SOURSES=$(SRC)/ftpcallback.c $(SRC)/ftpserver.c  ./ftpprotocol/ftpprotocol.c 

Debug:   Debug_OR_Release=Debug
Debug:   CFLAGS+=-g 
Debug:   SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Debug:   OBJ_F=$(OBJ)/$(Debug_OR_Release)

Release: Debug_OR_Release=Release
Release: CFLAGS+=-DNDEBUG -O2
Release: SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Release: OBJ_F=$(OBJ)/$(Debug_OR_Release)



all: Debug

Debug:   create_folders  ftpserver  Install  cleanDebug 
Release: create_folders  ftpserver  Install  cleanRelease




ftpserver: show_action  ftpserver.obj
	g++ -o ./ftpserver.exe ./$(OBJ_F)/*.o ../$(CM)/$(BIN)/Release/iterbintreeKM.a ../$(CM)/$(BIN)/Release/libgenericserver.a

show_action:
	@echo
	@echo "-----------------------------------"
	@echo "   PRODUCING FTP executable"
	@echo "-----------------------------------"
	@echo



ftpserver.obj  : $(SRC)/ftpcallback.c  $(SRC)/ftpserver.c $(SRC)/ftpserver.h $(SRC)/internalftpserver.h\
                                                          ./ftpprotocol/ftpprotocol.c  ./ftpprotocol/ftpprotocol.h
	$(CC)  $(CFLAGS) -I $(SRC) -I ../$(CM)/$(PB) -I./ftpprotocol $(SRC)/ftpcallback.c        -c  -o $(OBJ_F)/ftpcallback.o
	$(CC)  $(CFLAGS) -I $(SRC) -I ../$(CM)/$(PB) -I./ftpprotocol $(SRC)/ftpserver.c          -c  -o $(OBJ_F)/ftpserver.o
	$(CC)  $(CFLAGS) -I $(SRC) -I ../$(CM)/$(PB) -I./ftpprotocol ./ftpprotocol/ftpprotocol.c -c  -o $(OBJ_F)/ftpprotocol.o

create_folders:
	mkdir -p $(OBJ)/$(Debug_OR_Release) 
	mkdir -p $(BIN)/$(Debug_OR_Release)

Install:creat_instal_folders  CopyHfile 


CopyF: 
	cp $(BIN)/$(Debug_OR_Release)/libftpserver.a   ../$(CM)/$(BIN)/$(Debug_OR_Release)

CopyHfile:
	cp $(SRC)/ftpserver.h ../Common/$(PB)
		
creat_instal_folders:
	mkdir -p ../$(CM)/$(PB)
	mkdir -p ../$(CM)/$(BIN)/$(Debug_OR_Release)


cleanDebug:
	for i in $(SUBDIRS); do\
		(cd $$i; rm -f * );\
	done
	rm -f ./*.o

cleanRelease:
	for i in $(SUBDIRS); do\
		(cd $$i; rm -f * );\
	done
	rm -f ./*.o

